<?php
class Langs {

	var $CI;
	var $current_lang;
	
	function  __construct()
	{
		$this->CI =& get_instance();
		$this->CI->load->library('language');
		
		$this->CI->load->helper('directory');
		
		$this->init_lang();
	}

	function get_installed()
	{
		$langs = directory_map('./application/language/', TRUE);
		
		$inst_langs = array();
		
		foreach ($langs as $k => $v)
		{
			$inst_langs[$v] = $v;
		}
		
		return $inst_langs;
	}
	
	function fetch_file($filename)
	{
		$this->CI->lang->load($filename, $this->current_lang);
	}
	
	function init_lang()
	{
		if (!$this->CI->session->userdata("current_lang"))
		{
			$this->CI->session->set_userdata('current_lang', $this->CI->config->item('language'));
			$this->current_lang = $this->CI->config->item('language');
		}
		else
		{
			$this->current_lang = $this->CI->session->userdata("current_lang");
		}
		
		// Set current url for redirect
		$this->CI->session->set_flashdata('uri', $this->CI->uri->uri_string());
	}
	
	function change_lang($new_lang) 
	{
		$this->CI->session->set_userdata('current_lang', $new_lang);
		
	}

}
/* End of file lang.php */
/* Location: ./system/application/libraries/lang.php */
